package com.blue.example;

import com.blue.pojo.SendPackageVo;
import com.blue.pojo.WebApp;
import com.blue.pojo.WebConfigVo;
import com.blue.utils.*;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.paint.CycleMethod;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.Rectangle;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.DirectoryChooser;
import javafx.stage.DirectoryChooserBuilder;
import javafx.stage.Stage;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Administrator on 2019/7/9.
 */
public class Product extends Pane {

    public Stage stage = null;
    public BorderPane border = null;
    public String flagNum = null;
    public Text actiontargetText = new Text();
    public String installPath = "";
    public TextField installSysPath = new TextField();
    public TextField tomcatPortFiled = new TextField();
    final ProgressBar progressBar = new ProgressBar( 0 );
    private ProgressIndicator progressIndicator = new ProgressIndicator( 0 );
    public Label progressLable = new Label();
    private static String currentProjectName = "";
    //tomcat路径
    public String tomcatpath;
    public String tomcatPort;
    public String configPathImagePath = "";//文件按钮点击选择目录保存的值
    private Label tomcatPortLabel = new Label( "" );
    private Label installPathLabel = new Label( "" );
    public Button buttonInstall = new Button( "安装tomcat" );
    public Button buttonProjected = null;
    public CheckBox[] checkBoxes = new CheckBox[GlobalConfInfo.getProjectList().size()];
    public Boolean selected = false;
    public ArrayList<String> webList = new ArrayList();
    //web配置文本框
    public TextField[] webDataBaseIp = new TextField[GlobalConfInfo.getProjectList().size()];
    public TextField[] webDataBasePort = new TextField[GlobalConfInfo.getProjectList().size()];
    public TextField[] webDataBaseUser = new TextField[GlobalConfInfo.getProjectList().size()];
    public TextField[] webDataBasePass = new TextField[GlobalConfInfo.getProjectList().size()];
    public ArrayList<String> passList = new ArrayList();
    public StringBuffer selectFlags = new StringBuffer();

    //new
    public Button beginpage = null;
    public Button next = null;
    public CheckBox accept = null;
    public Button tomcatInstallation = null;
    public boolean installing = false;
    public boolean installationCompleted = false;
    public int count = 0;
    public Task<ArrayList<WebApp>> webAppDataTask = null;
    public ProgressFrom progressFrom = new ProgressFrom();
    public Label label = new Label();
    public GridPane grid = null;
    public TomcatHTMLUtil tomcatHTMLUtil;
    public VBox vBox;

    public String getTomcatpath() {
        return tomcatpath;
    }

    public void setTomcatpath(String tomcatpath) {
        this.tomcatpath = tomcatpath;
    }

    public String getTomcatPort() {
        return tomcatPort;
    }

    public void setTomcatPort(String tomcatPort) {
        this.tomcatPort = tomcatPort;
    }

    public ArrayList<String> getWebList() {
        return webList;
    }

    public void setWebList(ArrayList<String> webList) {
        this.webList = webList;
    }

    public StringBuffer getSelectFlags() {
        return selectFlags;
    }

    public void setSelectFlags(StringBuffer selectFlags) {
        this.selectFlags = selectFlags;
    }

    public Button getNext() {
        return next;
    }

    public void setNext(Button next) {
        this.next = next;
    }

    public Button getBeginpage() {
        return beginpage;
    }

    public void setBeginpage(Button beginpage) {
        this.beginpage = beginpage;
    }

    public Product() {
    }

    public Product(Stage primaryStage) {
        this.stage = primaryStage;
        this.border = new BorderPane();
        HBox hbox = addHBox();
        border.setTop( hbox );
        border.setLeft( addVBox() );
        addStackPane( hbox ); //添加一个堆栈面板到上方区域的HBox中

        //border.setCenter( addAnchorPane( addConfig() ) );
        /*GridPane tomcat = addTomcat( "Tomcat" );
        border.setCenter( addAnchorPane( tomcat,"Tomcat" ) );*/
        setCenter( border, "Tomcat" );
        //border.setRight( addAnchorPane(addproduct()) );
        this.getChildren().addAll( border );
    }

    public void setCenter(final BorderPane layout, String process) {
        GridPane tomcat = addTomcat( process );
        layout.setCenter( addAnchorPane( tomcat, process ) );
        if ("Tomcat".equals( process )) {
            buttonInstall.setOnAction( (ActionEvent e) -> {
                installTomcat( process );
            } );
        }
    }

    public HBox addHBox(String... s) {
        HBox hbox = new HBox();
        hbox.setPadding( new Insets( 15, 12, 15, 12 ) ); //节点到边缘的距离
        hbox.setSpacing( 10 ); //节点之间的间距
        hbox.setStyle( "-fx-background-color: #336699;" ); //背景色

        Button buttonCurrent = new Button( "current" );
        buttonCurrent.setOnAction( (ActionEvent e) -> {
            Product product = new Product( stage );
            Scene scene = new Scene( product, 950, 500 );
            stage.setScene( scene );
        } );
        buttonCurrent.setPrefSize( 100, 20 );

        buttonProjected = new Button( "next" );
        buttonProjected.setOnAction( new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                /*Product product = new Product( stage );
                Scene scene = new Scene( product );
                addHBoxproject();
                product.border.setTop( addHBoxproject() );
                product.border.setCenter( addAnchorPane( addproduct() ) );*/
                setCenterProject( stage, "default" );
                /*stage.setScene( scene );*/

            }
        } );
        buttonProjected.setPrefSize( 100, 20 );
        hbox.getChildren().addAll( buttonCurrent, buttonProjected );

        return hbox;
    }

    public void setCenterProject(final Stage stage, String process) {
        Product product = new Product( stage );
        Scene scene = new Scene( product );
        addHBoxproject();
        product.border.setTop( addHBoxproject() );
        product.border.setCenter( addAnchorPane( addproduct(), "default" ) );
        stage.setScene( scene );
        if ("default".equals( process )) {
            buttonInstall.setText( "Default Install" );
            buttonInstall.setDisable( true );
            buttonInstall.setOnAction( (ActionEvent e) -> {
                if (!"".equals( tomcatpath ) && null != tomcatpath) {
                    if (webList.isEmpty()) {
                        SBTFxDialog.showMessageDialog( stage, "请选择需要安装的项目！", "web项目安装提示" );
                    }
                    if (!webList.isEmpty()) {
                        installWebItem( webList, process );
                        //todo
                        //if (text.contains( "完成" )){
                        Boolean aBoolean = actTomcat();
                        if (aBoolean) {
                            SBTFxDialog.showMessageDialog( stage, "当前项目" + webList.toString() + "启动成功 !，请到浏览器访问*****!或返回点击next追加配置", "web项目成功启动提示" );
                            for (String webitem : webList) {
                                String war = GlobalConfInfo.getProjectMap().get( webitem ).split( "," )[1];
                                final String webname = war.substring( 0, war.lastIndexOf( "." ) );
                                switch (webitem) {
                                    case "product":
                                        BrowerUtils.broweruri( "http://localhost:" + tomcatPort + "/" + webname );
                                        break;
                                    case "DBMonitor":
                                        BrowerUtils.broweruri( "http://localhost:" + tomcatPort + "/" + webname + "/test" );
                                        break;
                                    case "Dmp":
                                        BrowerUtils.broweruri( "http://localhost:" + tomcatPort + "/" + webname + "/test" );
                                        break;
                                    case "Admp":
                                        BrowerUtils.broweruri( "http://localhost:" + tomcatPort + "/" + webname );
                                        break;
                                    case "education":
                                        BrowerUtils.broweruri( "http://localhost:" + tomcatPort + "/" + webname );
                                        break;
                                }
                            }
                        }

                    }
                } else {
                    SBTFxDialog.showMessageDialog( stage, "系统检测到Tomcat木有安装，请返回上一步安装Tomcat！", "web项目安装提示" );
                }
            } );
        }
    }

    public HBox addHBoxproject(String... s) {
        HBox hbox = new HBox();
        hbox.setPadding( new Insets( 15, 12, 15, 12 ) ); //节点到边缘的距离
        hbox.setSpacing( 10 ); //节点之间的间距
        hbox.setStyle( "-fx-background-color: #336699;" ); //背景色

        Button buttonCurrent = new Button( "current" );
        buttonCurrent.setOnAction( (ActionEvent e) -> {
            Product product = new Product( stage );
            Scene scene = new Scene( product, 950, 500 );
            stage.setScene( scene );
        } );
        buttonCurrent.setPrefSize( 100, 20 );

        buttonProjected = new Button( "next" );
        buttonProjected.setOnAction( new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                if ("".equals( selectFlags.toString() )) {
                    SBTFxDialog.showMessageDialog( stage, "请选择需要自定义安装的项目，否则请默认安装！", "web项目安装配置提示" );
                }
                if (!"".equals( selectFlags.toString() )) {
                    /*Product product = new Product( stage );
                    Scene scene = new Scene( product );
                    addHBoxConfig();
                    product.border.setTop( addHBoxConfig() );
                    product.border.setCenter( addAnchorPane( addConfig() ) );
                    stage.setScene( scene );*/
                    setCenterConfig( stage, "config" );
                }
            }
        } );
        buttonProjected.setPrefSize( 100, 20 );
        hbox.getChildren().addAll( buttonCurrent, buttonProjected );

        return hbox;
    }

    public void setCenterConfig(final Stage stage, String process) {
        Product product = new Product( stage );
        Scene scene = new Scene( product );
        addHBoxConfig();
        product.border.setTop( addHBoxConfig() );
        //product.border.setCenter( addAnchorPane( addConfig(), process ) );
        stage.setScene( scene );
        if ("config".equals( process )) {
            buttonInstall.setDisable( false );
            buttonInstall.setText( " 自定义Install" );
            buttonInstall.setOnAction( (ActionEvent e) -> {
                if (!"".equals( tomcatpath ) && null != tomcatpath) {
                    if (webList.isEmpty()) {
                        SBTFxDialog.showMessageDialog( stage, "请选择需要安装的项目！", "web项目安装提示" );
                    }
                    if (!webList.isEmpty()) {
                        installWebItem( webList, process );
                        /*try {
                            Thread.sleep( 2000 );
                        } catch (InterruptedException e1) {
                            e1.printStackTrace();
                        }*/

                        installWebConfig( webList, process );

                    }
                } else {
                    SBTFxDialog.showMessageDialog( stage, "系统检测到Tomcat木有安装，请返回上一步安装Tomcat！", "web项目安装提示" );
                }
            } );
        }
    }

    public HBox addHBoxConfig(String... s) {
        HBox hbox = new HBox();
        hbox.setPadding( new Insets( 15, 12, 15, 12 ) ); //节点到边缘的距离
        hbox.setSpacing( 10 ); //节点之间的间距
        hbox.setStyle( "-fx-background-color: #336699;" ); //背景色

        Button buttonCurrent = new Button( "current" );
        buttonCurrent.setOnAction( (ActionEvent e) -> {
            /*Product product = new Product( stage );
            Scene scene = new Scene( product );
            addHBoxproject();
            product.border.setTop( addHBoxproject() );
            product.border.setCenter( addAnchorPane( addproduct() ) );
            stage.setScene( scene );*/
            setCenterProject( stage, "default" );
        } );
        buttonCurrent.setPrefSize( 100, 20 );

        buttonProjected = new Button( "next" );
        buttonProjected.setOnAction( new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                /*Product product = new Product( stage );
                Scene scene = new Scene( product );
                product.border.setCenter( addAnchorPane( addConfig() ) );
                stage.setScene( scene );*/

            }
        } );
        buttonProjected.setPrefSize( 100, 20 );
        hbox.getChildren().addAll( buttonCurrent, buttonProjected );

        return hbox;
    }

    /*public void setCenterProjectFinished(final Stage stage, String process) {
        Product product = new Product( stage );
        Scene scene = new Scene( product );
        addHBoxproject();
        product.border.setTop( addHBoxproject() );
        product.border.setCenter( addAnchorPane( addwebPathShow(), "Finished" ) );
        stage.setScene( scene );

    }

    private GridPane addwebPathShow() {
    }*/


    public VBox addVBox() {
        VBox vbox = new VBox();
        vbox.setPadding( new Insets( 10 ) ); //内边距
        vbox.setSpacing( 8 ); //节点间距

        Text title = new Text( "安装步骤" );
        title.setFont( Font.font( "Arial", FontWeight.BOLD, 14 ) );
        vbox.getChildren().add( title );

        Hyperlink options[] = new Hyperlink[]{
                new Hyperlink( "安装TomCat" ),
                new Hyperlink( "安装BLUE产品" ),
                new Hyperlink( "自义定配置" ),
                new Hyperlink( "Costs" )};

        for (int i = 0; i < 4; i++) {
            VBox.setMargin( options[i], new Insets( 0, 0, 0, 8 ) ); //为每个节点设置外边距
            vbox.getChildren().add( options[i] );
        }

        return vbox;
    }


    public void addStackPane(HBox hb) {
        StackPane stack = new StackPane();
        Rectangle helpIcon = new Rectangle( 30.0, 25.0 );
        helpIcon.setFill( new LinearGradient( 0, 0, 0, 1, true, CycleMethod.NO_CYCLE,
                new Stop[]{
                        new Stop( 0, Color.web( "#4977A3" ) ),
                        new Stop( 0.5, Color.web( "#B0C6DA" ) ),
                        new Stop( 1, Color.web( "#9CB6CF" ) ),} ) );
        helpIcon.setStroke( Color.web( "#D0E6FA" ) );
        helpIcon.setArcHeight( 3.5 );
        helpIcon.setArcWidth( 3.5 );

        Text helpText = new Text( "?" );
        helpText.setFont( Font.font( "Verdana", FontWeight.BOLD, 18 ) );
        helpText.setFill( Color.WHITE );
        helpText.setStroke( Color.web( "#7080A0" ) );

        stack.getChildren().addAll( helpIcon, helpText );
        stack.setAlignment( Pos.CENTER_RIGHT ); //右对齐节点

        StackPane.setMargin( helpText, new Insets( 0, 10, 0, 0 ) ); //设置问号居中显示
        hb.getChildren().add( stack ); // 将StackPane添加到HBox中
        HBox.setHgrow( stack, Priority.ALWAYS ); // 将HBox水平多余的所有空间都给StackPane，这样前面设置的右对齐就能保证问号按钮在最右边
    }


    public GridPane addGridPane() {
        GridPane grid = new GridPane();
        grid.setHgap( 10 );
        grid.setVgap( 10 );
        grid.setPadding( new Insets( 0, 10, 0, 10 ) );

        // 将category节点放在第1行,第2列
        Text category = new Text( "Sales:" );
        category.setFont( Font.font( "Arial", FontWeight.BOLD, 20 ) );
        grid.add( category, 1, 0 );

        // 将chartTitle节点放在第1行,第3列
        Text chartTitle = new Text( "Current Year" );
        chartTitle.setFont( Font.font( "Arial", FontWeight.BOLD, 20 ) );
        grid.add( chartTitle, 2, 0 );

        // 将chartSubtitle节点放在第2行,占第2和第3列
        Text chartSubtitle = new Text( "Goods and Services" );
        grid.add( chartSubtitle, 1, 1, 2, 1 );

        // 将House图标放在第1列，占第1和第2行
        ImageView imageHouse = new ImageView(
                new Image( "/image/tomcat.png" ) );
        grid.add( imageHouse, 0, 0, 1, 2 );

        // 将左边的标签goodsPercent放在第3行，第1列，靠下对齐
        Text goodsPercent = new Text( "Goods\n80%" );
        GridPane.setValignment( goodsPercent, VPos.BOTTOM );
        grid.add( goodsPercent, 0, 2 );

        // 将饼图放在第3行，占第2和第3列
        ImageView imageChart = new ImageView(
                new Image( "/image/education.png" ) );
        grid.add( imageChart, 1, 2, 2, 1 );

        // 将右边的标签servicesPercent放在第3行，第4列，靠上对齐
        Text servicesPercent = new Text( "Services\n20%" );
        GridPane.setValignment( servicesPercent, VPos.TOP );
        grid.add( servicesPercent, 3, 2 );

        return grid;
    }


    public FlowPane addFlowPane() {
        FlowPane flow = new FlowPane();
        flow.setPadding( new Insets( 5, 0, 5, 0 ) );
        flow.setVgap( 4 );
        flow.setHgap( 4 );
        flow.setPrefWrapLength( 170 ); // 预设FlowPane的宽度，使其能够显示两列
        flow.setStyle( "-fx-background-color: DAE6F3;" );

        ImageView pages[] = new ImageView[5];
        for (int i = 0; i < 5; i++) {
            pages[i] = new ImageView(
                    new Image( "/img/book" + (i + 1) + ".jpg", 150, 100, false, false ) );
            flow.getChildren().add( pages[i] );
        }

        return flow;
    }

    public TilePane addTilePane() {

        TilePane tile = new TilePane();
        tile.setPadding( new Insets( 5, 0, 5, 0 ) );
        tile.setVgap( 4 );
        tile.setHgap( 4 );
        tile.setPrefColumns( 2 );
        tile.setStyle( "-fx-background-color: DAE6F3;" );

        ImageView pages[] = new ImageView[5];
        for (int i = 0; i < 5; i++) {
            pages[i] = new ImageView(
                    new Image(
                            "/img/book" + (i + 1) + ".jpg", 150, 100, false, false ) );
            tile.getChildren().add( pages[i] );
        }
        return tile;
    }


    public AnchorPane addAnchorPane(GridPane grid, String... projectName) {
        AnchorPane anchorpane = new AnchorPane();
        /*if ("Tomcat".equals( projectName )) {
            buttonInstall.setText( "Install Tomcat" );
        }
        if ("default".equals( projectName )) {
            buttonInstall.setText( "Default Install" );
        }
        if ("config".equals( projectName )) {
            buttonInstall.setText( "自定义安装" );
        }*/
        Button buttonCancel = new Button( "Cancel" );

        HBox hb = new HBox();
        hb.setPadding( new Insets( 0, 10, 10, 10 ) );
        hb.setSpacing( 10 );
        hb.getChildren().addAll( buttonInstall, buttonCancel );

        anchorpane.getChildren().addAll( grid, hb );
        AnchorPane.setBottomAnchor( hb, 8.0 );
        AnchorPane.setRightAnchor( hb, 5.0 );
        AnchorPane.setTopAnchor( grid, 10.0 );
        /*if ("Tomcat".equals( projectName )) {
            buttonInstall.setOnAction( (ActionEvent e) -> {
                installTomcat( projectName);
            } );
        }*/
        /*if ("default".equals( projectName )) {
            buttonInstall.setOnAction( (ActionEvent e) -> {

            } );
        }
        if ("config".equals( projectName )) {
            buttonInstall.setOnAction( (ActionEvent e) -> {

            } );
        }*/

        return anchorpane;
    }

    public BorderPane addBorderPaneWithCircle(GridPane grid, String... projectName) {
        BorderPane borderPane = new BorderPane();
        AnchorPane anchorpane = new AnchorPane();

        HBox hBoxLable = new HBox();
        hBoxLable.setPadding( new Insets( 0, 10, 10, 10 ) );
        hBoxLable.setSpacing( 190 );
        hBoxLable.setAlignment( Pos.CENTER_LEFT );
        Label firstStep = new Label( "第一步" );
        Label secondStep = new Label( "第二步" );
        Label thirdStep = new Label( "第三步" );
        //Label forthStep = new Label( "第四步" );
        hBoxLable.getChildren().addAll( firstStep, secondStep, thirdStep );

        HBox hBox = new HBox();
        hBox.setAlignment( Pos.CENTER_LEFT );
        for (int i = 0; i < 3; i++) {
            Line line1 = new Line();
            line1.setStrokeWidth( 5 );    //设置线的宽度
            line1.setStrokeLineCap( StrokeLineCap.ROUND );  //在线或路径的末尾设置帽样式 1.StrokeLineCap.BUTT 2.StrokeLineCap.ROUND 3.StrokeLineCap.SQUARE
            line1.getStrokeDashArray().addAll( 15d, 10d, 15d, 5d, 5d );  //设置短划线数组
            //line.setStrokeDashOffset(10);      // 将距离设置为虚线模式。
            line1.setStroke( Color.GREEN );
            line1.setStartX( 40f );
            line1.setStartY( 0f );
            line1.setEndX( 120.0f );
            line1.setEndY( 0f );

            Line line = new Line();
            line.setStrokeWidth( 5 );    //设置线的宽度
            line.setStrokeLineCap( StrokeLineCap.ROUND );  //在线或路径的末尾设置帽样式 1.StrokeLineCap.BUTT 2.StrokeLineCap.ROUND 3.StrokeLineCap.SQUARE
            line.getStrokeDashArray().addAll( 15d, 10d, 15d, 5d, 5d );  //设置短划线数组
            //line.setStrokeDashOffset(10);      // 将距离设置为虚线模式。
            line.setStroke( Color.GREEN );
            line.setStartX( 40f );
            line.setStartY( 0f );
            line.setEndX( 120.0f );
            line.setEndY( 0f );

            Circle circle = new Circle();
            circle.setCenterX( 20.0 );
            circle.setCenterY( 20.0 );
            circle.setRadius( 5.0 );
            circle.setStroke( Color.RED );
            circle.setFill( null );
            //circle.resize( 10.0,10.0 );

            hBox.getChildren().addAll( line1, circle, line );
        }

        VBox vBox = new VBox();
        vBox.setPadding( new Insets( 10 ) ); //内边距
        vBox.setSpacing( 8 );
        VBox.setMargin( hBoxLable, new Insets( 0, 0, 0, 8 ) ); //为每个节点设置外边距 );
        //vBox.getChildren().addAll( hBoxLable, hBox );

        next = new Button( "下一步" );
        Button pro = new Button( "上一步" );

        HBox hb = new HBox();
        hb.setPadding( new Insets( 0, 10, 10, 10 ) );
        hb.setSpacing( 10 );
        hb.getChildren().addAll( pro, next );

        anchorpane.getChildren().addAll( grid, hb );
        AnchorPane.setBottomAnchor( hb, 80.0 );
        AnchorPane.setRightAnchor( hb, 50.0 );
        AnchorPane.setTopAnchor( grid, 10.0 );

        borderPane.setTop( vBox );
        borderPane.setCenter( anchorpane );


        return borderPane;
    }

    public GridPane addTextexplain() {
        GridPane grid = new GridPane();
        grid.setHgap( 10 );
        grid.setVgap( 10 );
        grid.setPadding( new Insets( 0, 10, 0, 10 ) );

        StackPane stack = new StackPane();
        Rectangle helpIcon = new Rectangle( 800.0, 300.0 );
        helpIcon.setFill( Color.WHITE );
        /*helpIcon.setFill( new LinearGradient( 0, 0, 0, 1, true, CycleMethod.NO_CYCLE,
                new Stop[]{
                        new Stop( 0, Color.web( "#4977A3" ) ),
                        new Stop( 0.5, Color.web( "#B0C6DA" ) ),
                        new Stop( 1, Color.web( "#9CB6CF" ) ),} ) );*/
        helpIcon.setStroke( Color.web( "#D0E6FA" ) );
        helpIcon.setArcHeight( 3.5 );
        helpIcon.setArcWidth( 3.5 );

        Text helpText = new Text( "安装许可协议\n1.***********************\n2.**********************" +
                "\n3.-************************************" );
        helpText.setFont( Font.font( "Verdana", FontWeight.BOLD, 18 ) );
        helpText.setFill( Color.BLACK );
        helpText.setStroke( Color.web( "#7080A0" ) );

        stack.getChildren().addAll( helpIcon, helpText );
        stack.setAlignment( Pos.TOP_LEFT ); //右对齐节点

        StackPane.setMargin( helpText, new Insets( 0, 10, 0, 0 ) ); //设置问号居中显示

        // 将category节点放在第1行,第2列

        grid.add( stack, 1, 0 );
        accept = new CheckBox( "接受BLUE安装许可协议" );
        accept.setStyle( "-fx-font: 15 arial;" );
        /*beginpage = new Button( "开始安装" );
        //button.setStyle( "-fx-font: 20 arial; -fx-base: #ee2211;" );
        DropShadow shadow = new DropShadow();
        beginpage.setEffect( shadow );*/


        grid.add( accept, 1, 1 );
        //grid.add( beginpage, 1, 2 );

        return grid;
    }


    /**
     * install TomCat
     *
     * @return
     */
    public GridPane addTomcat(String projectName) {
        //flagNum = "2";
        GridPane grid = new GridPane();
        grid.setHgap( 10 );
        grid.setVgap( 10 );
        grid.setPadding( new Insets( 0, 10, 0, 10 ) );

        //进度条显示
        VBox projectVbox = new VBox();
        projectVbox.setSpacing( 5 );
        projectVbox.setStyle( "-fx-background-color:#fff" );
        currentProjectName = projectName;


        //进度条
        VBox progressVBox = new VBox();
        progressVBox.setPadding( new Insets( 0, 12, 0, 0 ) );
        String zipName = GlobalConfInfo.getProjectMap().get( projectName ).split( "," )[1];
        zipName = zipName.substring( 0, zipName.lastIndexOf( "." ) );
        progressBar.setMinWidth( 700 );
        progressBar.setMinHeight( 18 );
        progressLable.setStyle( "-fx-padding:5 0 0 10px" );
        //进度条绑定Label 显示进度
        VBox proVbox = new VBox();
        proVbox.getChildren().addAll( progressBar, progressLable );
        HBox hb = new HBox( 0 );
        hb.setPadding( new Insets( 0, 12, 0, 0 ) );
        Label installLabel = new Label( zipName + "安装进度：" );
        hb.getChildren().addAll(/*installLabel,*/proVbox/*, progressIndicator*/ );
        progressVBox.getChildren().addAll( hb );

        //tomcat 自定义安装路径
        /* Tomcat安装目录 start */
        //安装目录选择
        VBox pathVBox = new VBox( 5 );
        pathVBox.setPadding( new Insets( 0, 12, 0, 23 ) );
        HBox pathHBox = new HBox( 10 );
        Label pathFiledLabel = new Label( "安装目录：" );
        pathFiledLabel.setStyle( "-fx-padding:4 0 0 0px" );
        installSysPath.setPrefColumnCount( 39 );  //设置偏爱的文本框宽度
        //todo
        System.out.println( "先前输入的tomcat路径为：" + configPathImagePath );
        if (!"".equals( configPathImagePath ) && null != configPathImagePath) {
            installSysPath.setText( configPathImagePath );
        } else {
            installSysPath.setPromptText( currentProjectName + "的安装目录" );
        }
        //文件夹选择按钮
        final Button fileDectorybtn = new Button();
        fileDectorybtn.setText( "选取目录" );
        fileDectorybtn.getStyleClass().add( "file-button" );
        fileDectorybtn.setOnAction( new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {
                DirectoryChooserBuilder builder = DirectoryChooserBuilder.create();
                String cwd = System.getProperty( "user.dir" );
                File file = new File( cwd );
                builder.initialDirectory( file );
                DirectoryChooser chooser = builder.build();
                File chosenDir = chooser.showDialog( stage );
                if (chosenDir != null) {
                    configPathImagePath = chosenDir.getAbsolutePath();
                    installSysPath.setText( configPathImagePath );
                    System.out.println( "目录选择---->" + configPathImagePath );
                } else {
                    System.out.print( "no directory chosen" );
                }
            }
        } );

        //installPathLabel.setStyle( "-fx-padding:10 0 0 0px" );
        pathHBox.getChildren().addAll( pathFiledLabel, installSysPath, fileDectorybtn );
        pathVBox.getChildren().addAll( pathHBox, installPathLabel );

        //tomcat端口自定义
        //启动端口
        VBox centervb = new VBox( 5 );
        centervb.setPadding( new Insets( 0, 12, 0, 23 ) );
        HBox center_hb = new HBox( 10 );
        center_hb.setPadding( new Insets( 5, 12, 0, 0 ) );
        Label label1 = new Label( "启动端口：" );
        label1.setStyle( "-fx-padding:4 0 0 0px" );
        tomcatPortFiled.setPrefColumnCount( 14 );  //设置偏爱的文本框宽度
        tomcatPortFiled.setPromptText( "Tomcat端口范围:1~65535" );
        HBox insButtompan = new HBox();
        insButtompan.setPadding( new Insets( 5, 12, 0, 0 ) );
        tomcatInstallation = new Button( "Installation" );
        tomcatInstallation.prefWidth( 100 );
        tomcatInstallation.prefHeight( 20 );
        HBox.setMargin( tomcatInstallation, new Insets( 0, 0, 0, 280 ) );
        insButtompan.getChildren().addAll( tomcatInstallation );
        center_hb.getChildren().addAll( label1, tomcatPortFiled, insButtompan );
        centervb.getChildren().addAll( center_hb, tomcatPortLabel );
        //添加到布局
        projectVbox.getChildren().addAll( progressVBox, pathVBox, centervb );

        //将projectVbox放到grid
        grid.add( projectVbox, 1, 1, 2, 1 );

        // 将category节点放在第1行,第2列
        /*Text category = new Text( "Sales:" );
        category.setFont( Font.font( "Arial", FontWeight.BOLD, 20 ) );
        grid.add( category, 1, 0 );*/

        // 将chartTitle节点放在第1行,第3列
        /*Text chartTitle = new Text( "Current Year" );
        chartTitle.setFont( Font.font( "Arial", FontWeight.BOLD, 20 ) );
        grid.add( chartTitle, 2, 0 );*/

        // 将chartSubtitle节点放在第2行,占第2和第3列
        /*Text chartSubtitle = new Text( "Goods and Services" );
        grid.add( chartSubtitle, 1, 1, 2, 1 );*/

        // 将tomcat图标放在第1列，占第1和第2行
        ImageView imageHouse = new ImageView(
                new Image( "/image/tomcat.png" ) );
        grid.add( imageHouse, 0, 0, 1, 2 );

        // 将左边的标签goodsPercent放在第3行，第1列，靠下对齐
       /* Text goodsPercent = new Text( "Goods\n80%" );
        GridPane.setValignment( goodsPercent, VPos.BOTTOM );
        grid.add( goodsPercent, 0, 2 );*/

        // 将饼图放在第3行，占第2和第3列
        /*ImageView imageChart = new ImageView(
                new Image( "/image/education.png" ) );
        grid.add( imageChart, 1, 2, 2, 1 );*/

        // 将右边的标签servicesPercent放在第3行，第4列，靠上对齐
        /*Text servicesPercent = new Text( "Services\n20%" );
        GridPane.setValignment( servicesPercent, VPos.TOP );
        grid.add( servicesPercent, 3, 2 );*/

        return grid;
    }

    /**
     * 展示产品
     *
     * @return
     */
    public GridPane addproductnew() {
        flagNum = "1";
        GridPane grid = new GridPane();
        grid.setHgap( 10 );
        grid.setVgap( 10 );
        grid.setPadding( new Insets( 0, 10, 0, 10 ) );

        TilePane tile = new TilePane();
        tile.setPadding( new Insets( 5, 0, 5, 0 ) );
        tile.setVgap( 4 );
        tile.setHgap( 4 );
        tile.setPrefColumns( 3 );
        tile.setStyle( "-fx-background-color: DAE6F3;" );

        StackPane[] stackPane = new StackPane[GlobalConfInfo.getProjectList().size()];

        ImageView pages[] = new ImageView[GlobalConfInfo.getProjectList().size()];
        //CheckBox[] checkBoxes = new CheckBox[GlobalConfInfo.getProjectList().size()];
        for (int i = 0; i < GlobalConfInfo.getProjectList().size(); i++) {
            int a = i;
            stackPane[i] = new StackPane();
            checkBoxes[i] = new CheckBox();
            pages[i] = new ImageView(
                    new Image(//todo linux下资源找不到
                            "/image/" + GlobalConfInfo.getProjectList().get( i ) + ".png", 150, 100, false, false ) );
            //Image image = new Image( "/img/book" + (i + 1) + ".jpg", 150, 100, false, false ); );
            stackPane[i].getChildren().addAll( pages[i], checkBoxes[i] );
            StackPane.setMargin( checkBoxes[i], new Insets( 0, 0, 84, 140 ) );
            if (selectFlags.toString().indexOf( String.valueOf( a ) ) > -1) {
                checkBoxes[i].setSelected( true );
            }
            checkBoxes[i].selectedProperty().addListener( (ObservableValue<? extends Boolean> ov,
                                                           Boolean old_val, Boolean new_val) -> {
                if (new_val) {
                    selectFlags.append( a + "/" );
                    System.out.println( "选中的项目下标为：" + selectFlags.toString() );
                    webList.add( GlobalConfInfo.getProjectList().get( a ) );
                    for (String s : webList
                            ) {
                        System.out.println( "选择的项目名为：" + s );
                    }
                    //todo
                    //webList.trimToSize();
                }
                if (old_val) {
                    int of = selectFlags.indexOf( String.valueOf( a ) );
                    selectFlags.delete( of, of + 2 );
                    webList.remove( a );
                    //todo
                    //webList.trimToSize();//设置此项数组会越界todo
                }

            } );

            //tile.getChildren().add( pages[i] );

        }
        tile.getChildren().addAll( stackPane );
        grid.add( tile, 0, 0, 2, 2 );
        return grid;
    }

    /**
     * 展示产品
     *
     * @return
     */
    public GridPane addproduct() {
        //flagNum = "1";
        GridPane grid = new GridPane();
        grid.setHgap( 10 );
        grid.setVgap( 10 );
        grid.setPadding( new Insets( 0, 10, 0, 10 ) );

        TilePane tile = new TilePane();
        tile.setPadding( new Insets( 5, 0, 5, 0 ) );
        tile.setVgap( 4 );
        tile.setHgap( 4 );
        tile.setPrefColumns( 3 );
        tile.setStyle( "-fx-background-color: DAE6F3;" );

        StackPane[] stackPane = new StackPane[GlobalConfInfo.getProjectList().size()];

        ImageView pages[] = new ImageView[GlobalConfInfo.getProjectList().size()];
        //CheckBox[] checkBoxes = new CheckBox[GlobalConfInfo.getProjectList().size()];
        for (int i = 0; i < GlobalConfInfo.getProjectList().size(); i++) {
            int a = i;
            stackPane[i] = new StackPane();
            checkBoxes[i] = new CheckBox();
            pages[i] = new ImageView(
                    new Image(//todo linux下资源找不到
                            "/image/" + GlobalConfInfo.getProjectList().get( i ) + ".png", 150, 100, false, false ) );
            //Image image = new Image( "/img/book" + (i + 1) + ".jpg", 150, 100, false, false ); );
            stackPane[i].getChildren().addAll( pages[i], checkBoxes[i] );
            StackPane.setMargin( checkBoxes[i], new Insets( 0, 0, 84, 140 ) );
            if (selectFlags.toString().indexOf( String.valueOf( a ) ) > -1) {
                checkBoxes[i].setSelected( true );
            }
            checkBoxes[i].selectedProperty().addListener( (ObservableValue<? extends Boolean> ov,
                                                           Boolean old_val, Boolean new_val) -> {
                if (new_val) {
                    selectFlags.append( a + "/" );
                    System.out.println( "选中的项目下标为：" + selectFlags.toString() );
                    webList.add( GlobalConfInfo.getProjectList().get( a ) );
                    for (String s : webList
                            ) {
                        System.out.println( "选择的项目名为：" + s );
                    }
                    //todo
                    //webList.trimToSize();
                }
                if (old_val) {
                    int of = selectFlags.indexOf( String.valueOf( a ) );
                    selectFlags.delete( of, of + 2 );
                    webList.remove( a );
                    //todo
                    //webList.trimToSize();//设置此项数组会越界todo
                }

            } );

            //tile.getChildren().add( pages[i] );

        }
        tile.getChildren().addAll( stackPane );
        grid.add( tile, 0, 0, 2, 2 );
        return grid;
    }

    /**
     * add config
     *
     * @return
     */
    public GridPane addConfig() {
        grid = new GridPane();
        grid.setHgap( 10 );
        grid.setVgap( 10 );
        grid.setPadding( new Insets( 0, 10, 0, 10 ) );

        //各个web产品自定义配置项
        VBox configVbox = new VBox();
        configVbox.setSpacing( 5 );
        configVbox.setStyle( "-fx-background-color:#fff" );
        /*VBox[] centervb = new VBox[GlobalConfInfo.getProjectList().size()];
        VBox[] last = new VBox[GlobalConfInfo.getProjectList().size()];
        HBox[] center_hb = new HBox[GlobalConfInfo.getProjectList().size()];
        HBox[] center_hb_sec = new HBox[GlobalConfInfo.getProjectList().size()];*/

        String[] strings = selectFlags.toString().split( "/" );
        VBox[] centervb = new VBox[strings.length];
        VBox[] last = new VBox[strings.length];
        HBox[] center_hb = new HBox[strings.length];
        HBox[] center_hb_sec = new HBox[strings.length];


        /*for (int i = 0; i < GlobalConfInfo.getProjectList().size(); i++) {
            centervb[i] = new VBox( 5 );
            centervb[i].setPadding( new Insets( 0, 12, 0, 23 ) );
            center_hb[i] = new HBox( 10 );
            center_hb[i].setPadding( new Insets( 5, 12, 0, 0 ) );
            last[i] = new VBox( 5 );
            last[i].setPadding( new Insets( 0, 12, 0, 23 ) );
            center_hb_sec[i] = new HBox( 10 );
            center_hb_sec[i].setPadding( new Insets( 5, 12, 0, 0 ) );

            Label label = new Label( GlobalConfInfo.getProjectList().get( i ) + "产品配置" );
            Label webDataBaseIpLabel = new Label( "数据库IP" );
            Label webDataBasePortLabel = new Label( "数据库端口" );
            Label webDataBaseUserLabel = new Label( "数据库用户名" );
            Label webDataBasePassLabel = new Label( "数据库密码" );
            webDataBaseIpLabel.setStyle( "-fx-padding:4 0 0 0px" );
            webDataBasePortLabel.setStyle( "-fx-padding:4 0 0 0px" );
            webDataBaseIp[i] = new TextField();
            webDataBaseIp[i].setPrefColumnCount( 14 );  //设置偏爱的文本框宽度
            webDataBaseIp[i].setPromptText( "请输入当前项目的数据库IP" );
            webDataBasePort[i] = new TextField( "3306" );
            webDataBasePort[i].setPrefColumnCount( 14 );  //设置偏爱的文本框宽度
            webDataBasePort[i].setPromptText( "请输入当前项目的数据库端口" );
            webDataBaseUser[i] = new TextField();
            webDataBaseUser[i].setPrefColumnCount( 14 );  //设置偏爱的文本框宽度
            webDataBaseUser[i].setPromptText( "请输入当前项目的数据库用户名" );
            webDataBasePass[i] = new TextField();
            webDataBasePass[i].setPrefColumnCount( 14 );  //设置偏爱的文本框宽度
            webDataBasePass[i].setPromptText( "请输入当前项目的数据库密码" );
            center_hb[i].getChildren().addAll( webDataBaseIpLabel, webDataBaseIp[i], webDataBasePortLabel, webDataBasePort[i] );
            center_hb_sec[i].getChildren().addAll( webDataBaseUserLabel, webDataBaseUser[i], webDataBasePassLabel, webDataBasePass[i] );
            centervb[i].getChildren().addAll( center_hb[i], center_hb_sec[i] );
            last[i].getChildren().addAll( label, centervb[i] );

        }*/
        //String[] strings = selectFlags.toString().split( "/" );
        Integer[] integer = new Integer[strings.length];
        for (int i = 0; i < strings.length; i++) {
            integer[i] = Integer.parseInt( strings[i] );
        }
        Arrays.sort( integer );
        for (int i = 0; i < strings.length; i++) {
            int i1 = integer[i];

            for (int j = 0; j < GlobalConfInfo.getProjectList().size(); j++) {
                if (j < i1) {
                    continue;
                }
                if (j == i1) {
                    centervb[i] = new VBox( 5 );
                    centervb[i].setPadding( new Insets( 0, 12, 0, 23 ) );
                    center_hb[i] = new HBox( 10 );
                    center_hb[i].setPadding( new Insets( 5, 12, 0, 0 ) );
                    last[i] = new VBox( 5 );
                    last[i].setPadding( new Insets( 0, 12, 0, 23 ) );
                    center_hb_sec[i] = new HBox( 10 );
                    center_hb_sec[i].setPadding( new Insets( 5, 12, 0, 0 ) );

                    Label label = new Label( GlobalConfInfo.getProjectList().get( i1 ) + "产品配置" );
                    Label webDataBaseIpLabel = new Label( "数据库IP" );
                    Label webDataBasePortLabel = new Label( "数据库端口" );
                    Label webDataBaseUserLabel = new Label( "数据库用户名" );
                    Label webDataBasePassLabel = new Label( "数据库密码" );
                    webDataBaseIpLabel.setStyle( "-fx-padding:4 0 0 0px" );
                    webDataBasePortLabel.setStyle( "-fx-padding:4 0 0 0px" );
                    webDataBaseIp[i] = new TextField();
                    webDataBaseIp[i].setPrefColumnCount( 14 );  //设置偏爱的文本框宽度
                    webDataBaseIp[i].setPromptText( "请输入数据库IP" );
                    webDataBasePort[i] = new TextField( "3306" );
                    webDataBasePort[i].setPrefColumnCount( 14 );  //设置偏爱的文本框宽度
                    webDataBasePort[i].setPromptText( "请输入数据库端口" );
                    webDataBaseUser[i] = new TextField( "root" );
                    webDataBaseUser[i].setPrefColumnCount( 14 );  //设置偏爱的文本框宽度
                    webDataBaseUser[i].setPromptText( "请输入数据库用户名" );
                    webDataBasePass[i] = new TextField();
                    webDataBasePass[i].setPrefColumnCount( 14 );  //设置偏爱的文本框宽度
                    webDataBasePass[i].setPromptText( "请输入数据库密码" );
                    center_hb[i].getChildren().addAll( webDataBaseIpLabel, webDataBaseIp[i], webDataBasePortLabel, webDataBasePort[i] );
                    center_hb_sec[i].getChildren().addAll( webDataBaseUserLabel, webDataBaseUser[i], webDataBasePassLabel, webDataBasePass[i] );
                    centervb[i].getChildren().addAll( center_hb[i], center_hb_sec[i] );
                    last[i].getChildren().addAll( label, centervb[i] );

                }

            }

        }
        //添加到布局
        configVbox.getChildren().addAll( last );
        grid.add( configVbox, 0, 0, 3, 3 );
        /*VBox vBox = progressFrom.addProcess( stage, label );
        grid.add( vBox, 1, 3 );*/
        return grid;
    }

    /*******************************华丽的分割线*****************************************************/
    /**
     * install tomcat process
     *
     * @param processName
     */
    public void installTomcat(String... processName) {
        boolean fillFlag = false;
        //String installPath = "";
        SendPackageVo sendPackageVo = new SendPackageVo();
        if (installSysPath.getText() != null && !installSysPath.getText().isEmpty()) {
            // user_Name= userTextField.getText();
            installPath = installSysPath.getText();
            if (StringUtils.isWindowPath( installPath )) {
                installPathLabel.setText( "" );
                sendPackageVo.setFilePath( installPath );
                //获取tomcat完整安装路径
                String zipName = GlobalConfInfo.getProjectMap().get( currentProjectName ).split( "," )[1];
                zipName = zipName.substring( 0, zipName.lastIndexOf( "." ) );
                tomcatpath = installPath + "\\" + zipName;
                tomcatPort = tomcatPortFiled.getText();
            } else {
                installPathLabel.setText( "" );
                sendPackageVo.setFilePath( installPath );
                //获取tomcat完整安装路径
                String zipName = GlobalConfInfo.getProjectMap().get( currentProjectName ).split( "," )[1];
                zipName = zipName.substring( 0, zipName.lastIndexOf( "." ) );
                zipName = zipName.substring( 0, zipName.lastIndexOf( "." ) );
                tomcatpath = installPath + "/" + zipName;
                tomcatPort = tomcatPortFiled.getText();
                //installPathLabel.setText( "安装目录格式错误 !" );
            }
        } else {
            installPathLabel.setText( "安装目录不能为空 !" );
            fillFlag = true;
        }
        installPathLabel.setStyle( "-fx-text-fill: red;" );
        tomcatPortLabel.setStyle( "-fx-text-fill: red;" );
        //Tomcat安装
        if (currentProjectName.contains( "Tomcat" )) {
            String settingPost = "";
            if (tomcatPortFiled.getText() != null && !tomcatPortFiled.getText().isEmpty()) {
                settingPost = tomcatPortFiled.getText();
                System.out.println( " ----------------- >>> " + settingPost );
                sendPackageVo.setPort( settingPost );
            }

            if (tomcatPortFiled.getText() != null && !tomcatPortFiled.getText().isEmpty()) {
                sendPackageVo.setFileName( GlobalConfInfo.getProjectMap().get( currentProjectName ).split( "," )[1] );

                // installBtn.disableProperty();
                if (StringUtils.isNumeric( tomcatPortFiled.getText() )) {

                    SendPackageToPath sendPackage = new SendPackageToPath( sendPackageVo, progressBar, progressLable );
                    Task task = null;
                    try {
                        task = sendPackage.sendPackageInfoByTask( currentProjectName, installPath );
                    } catch (IOException e) {
                        e.printStackTrace();
                        SBTFxDialog.showMessageDialog( stage, "请检查" + currentProjectName + "的安装目录是否存在 ...", "安装目录提示" );
                    }

                    progressBar.progressProperty().bind( task.progressProperty() );

                    progressLable.textProperty().bind( task.messageProperty() );

                    progressIndicator.progressProperty().bind( task.progressProperty() );
                    Thread thread = new Thread( task );
                    thread.start();
                    sendPackage.setInstallBtn( buttonInstall );

                } else {
                    tomcatPortLabel.setText( "Tomcat端口号输入不正确，请确认后再安装 ！" );
                }
                tomcatPortLabel.setText( "" );
            } else {
                tomcatPortLabel.setText( currentProjectName + "端口号不能为空 !" );
            }
        }

    }

    /**
     * install webitems process
     *
     * @param process
     */
    private void installWebItem(List<String> list, String... process) {
        for (int i = 0; i < list.size(); i++) {
            String[] wars = GlobalConfInfo.getProjectMap().get( list.get( i ) ).split( "," )[1].split( ":" );
            for (int j = 0; j < wars.length; j++) {
                SendPackageVo sendPackageVo = new SendPackageVo();
                sendPackageVo.setFilePath( tomcatpath );
                //sendPackageVo.setFileName( GlobalConfInfo.getProjectMap().get( list.get( i ) ).split( "," )[1] );
                sendPackageVo.setFileName( wars[j] );
                SendPackageToPath sendPackageToPath = new SendPackageToPath( sendPackageVo, progressBar, progressLable );
                Task task = null;
                try {
                    task = sendPackageToPath.sendPackageInfoByTaskWithWeb( list.get( i ) );
                } catch (IOException e) {
                    SBTFxDialog.showMessageDialog( stage, "请检查" + list.get( i ) + "安装目录是否存在 !", "安装目录提示" );
                }
                progressBar.progressProperty().bind( task.progressProperty() );

                progressLable.textProperty().bind( task.messageProperty() );

                progressIndicator.progressProperty().bind( task.progressProperty() );
                Thread thread = new Thread( task );
                thread.start();
                sendPackageToPath.setInstallBtn( buttonInstall );
            }
        }
        /*String text = buttonInstall.getText();
        System.out.println( "安装完成后的按钮名：" + text);
        return text;*/
    }

    /**
     * 自定义配置安装项目
     *
     * @param webList
     * @param process
     */
    private void installWebConfig(ArrayList<String> webList, String process) {

        boolean updatePro = false;
        boolean reloadWebFront = false;
        boolean updateSuccess = false;
        InetAddress address = null;
        String hostAddress = "";
        Boolean heartbeat2 = false;
        Boolean heartbeat = BatUtils.heartbeat2( tomcatPort );
        if (!heartbeat) {
            heartbeat2 = actTomcat();
            System.out.println( "actTomcat() heartbeat*******" + heartbeat2 );
        }
        System.out.println( "append config heartbeat*******" + heartbeat );
        if (heartbeat || heartbeat2) {
            for (int i = 0; i < webList.size(); i++) {
                String text1 = webDataBaseUser[i].getText();
                String text = webDataBasePass[i].getText();
                String ip = webDataBaseIp[i].getText();
                String port = webDataBasePort[i].getText();
                System.out.println( "username************" + text1 );
                System.out.println( "password************" + text );
                System.out.println( "username************" + ip );
                System.out.println( "password************" + port );
                if (null != text && !"".equals( text ) && null != text1 && !"".equals( text1 )) {
                    Boolean heartbeat1 = BatUtils.heartbeat();
                    System.out.println( "second heartbeat***********" + heartbeat1 );
                    if (heartbeat1) {
                        int warLength = GlobalConfInfo.getProjectMap().get( webList.get( i ) ).split( "," )[1]
                                .split( ":" ).length;
                        if (1 == warLength) {
                            String war = GlobalConfInfo.getProjectMap().get( webList.get( i ) ).split( "," )[1];
                            String webName = war.substring( 0, war.lastIndexOf( "." ) );
                            String path = tomcatpath + "/webapps/" + webName + "/WEB-INF/classes/application.properties";
                            Configuration configuration = new Configuration( path );
                            //String value = "jdbc:mysql://" + text + ":3306/hrms?useUnicode=true&characterEncoding=UTF-8&useSSL=false";
                            String user = text1;
                            String passw = text;
                            if (!updatePro) {
                                SBTFxDialog.showMessageDialog( stage, "当前项目" + webList.get( i ) + "正在更新数据源配置，请耐心等待！", webList.get( i ) + "项目配置提示" );
                            }
                            updatePro = configuration.updatePros( path, "spring.datasource.username", user, "spring.datasource.password", passw );
                            if (updatePro) {
                                boolean reloadWebApp = TomcatHTMLUtil.reloadWebApp( webName, tomcatPort );
                                if (reloadWebApp) {
                                    SBTFxDialog.showMessageDialog( stage, "当前项目" + webList.get( i ) + "启动成功 !，请到浏览器访问*****", "web项目成功启动提示" );
                                }
                            }
                        }
                        if (2 == warLength) {
                            //makesure all webApps loadded
                            String[] webApps = GlobalConfInfo.getProjectMap().get( webList.get( i ) ).split( "," )[1]
                                    .split( ":" );
                            String[] webAppNames = new String[webApps.length];
                            for (int j = 0; j < webApps.length; j++) {
                                String webAppWar = GlobalConfInfo.getProjectMap().get( webList.get( i ) ).split( "," )[1]
                                        .split( ":" )[j];
                                String webAppName = webAppWar.substring( 0, webAppWar.lastIndexOf( "." ) );
                                webAppNames[j] = webAppName;
                                System.out.println( "need to load webs : " + webAppNames[j] );
                            }
                            //Don't accuse me of writing duplicate code
                            String webFrontWar = GlobalConfInfo.getProjectMap().get( webList.get( i ) ).split( "," )[1]
                                    .split( ":" )[0];
                            String webFront = webFrontWar.substring( 0, webFrontWar.lastIndexOf( "." ) );
                            String webdatatWar = GlobalConfInfo.getProjectMap().get( webList.get( i ) ).split( "," )[1]
                                    .split( ":" )[1];
                            String webData = webdatatWar.substring( 0, webdatatWar.lastIndexOf( "." ) );
                            //ProgressFrom progressFrom = new ProgressFrom( stage, new Label( "当前项目" + webList.get( i ) + "正在加载，请耐心等候..." ) );
                            /*ArrayList<WebApp> webAppData = TomcatHTMLUtil.getTomcatWebAppDatasLoading( tomcatPort, webAppNames ,stage,
                                    new Label( "当前项目" + webList.get( i ) + "正在加载，请耐心等候..." ) );*/
                            WebConfigVo webConfigVo = new WebConfigVo( text1, text, ip, port );
                            tomcatHTMLUtil = new TomcatHTMLUtil( tomcatpath, tomcatPort, webFront,
                                    webData, webList, i, webConfigVo );
                            webAppDataTask = tomcatHTMLUtil.getTomcatWebAppDatasTask21( webAppNames );
                            //ProgressFrom progressFrom = new ProgressFrom( webAppDataTask, stage, new Label( "当前项目" + webList.get( i ) + "正在加载，请耐心等候..." ) );
                            label.textProperty().unbind();
                            label.textProperty().bind( webAppDataTask.messageProperty() );
                            Thread addconfig = new Thread( webAppDataTask, "addconfig" );
                            addconfig.start();
                            webAppDataTask.setOnSucceeded( e -> {
                                label.textProperty().unbind();
                                // this message will be seen.
                            } );
                            webAppDataTask.messageProperty().addListener( (observable, oldValue, newValue) -> {
                                System.out.println( " The current count is " + tomcatHTMLUtil.getCount() );
                                System.out.println( " The message of the current task is " + webAppDataTask.messageProperty() );
                                System.out.println( newValue );
                                if (/*5 == tomcatHTMLUtil.getCount() &&*/ "Done!".equals( newValue )) {
                                    count = tomcatHTMLUtil.getCount();
                                    grid.getChildren().removeAll( vBox );
                                    try {
                                        Thread.sleep( 2000 );
                                    } catch (InterruptedException e) {
                                        e.printStackTrace();
                                    }
                                    Alert alert = new Alert( Alert.AlertType.INFORMATION );
                                    alert.setTitle( "提示" );
                                    alert.setContentText( "当前项目" + webList.get( tomcatHTMLUtil.getN() ) + "启动成功 !，请到浏览器访问*****" );
                                    alert.showAndWait();
                                    if (StringUtils.isWindowPath( tomcatpath )) {
                                        for (String webitem : webList) {
                                            switch (webitem) {
                                                case "product":
                                                    BrowerUtils.broweruri( "http://localhost:" + tomcatPort + "/" + webFront );
                                                    break;
                                                case "a":
                                                    BrowerUtils.broweruri( "http://localhost:" + tomcatPort + "/" + webFront );
                                                    break;
                                                case "b":
                                                    BrowerUtils.broweruri( "http://localhost:" + tomcatPort + "/" + webFront );
                                                    break;
                                                case "c":
                                                    BrowerUtils.broweruri( "http://localhost:" + tomcatPort + "/" + webFront );
                                                    break;
                                                case "education":
                                                    BrowerUtils.broweruri( "http://localhost:" + tomcatPort + "/" + webFront );
                                                    break;
                                            }
                                        }
                                    }
                                }
                            } );

                            ArrayList<WebApp> webAppData = null;
                            /*try {
                                webAppData = webAppDataTask.get();
                                for (WebApp web : webAppData
                                        ) {
                                    System.out.println( "load webApps successfully : " + web.getName() );
                                    System.out.println( "load webApps' status  : " + web.getStatus() );
                                    if (webFront.equals( web.getName() ) && "运行".equals( web.getStatus() )) {
                                        //update front web project basePath
                                    *//*String webFrontWar = GlobalConfInfo.getProjectMap().get( webList.get( i ) ).split( "," )[1]
                                            .split( ":" )[0];
                                    String webFront = webFrontWar.substring( 0, webFrontWar.lastIndexOf( "." ) );*//*
                                        String path = tomcatpath + "//webapps//" + webFront + "//static//globalParams.json";
                                        String pathNew = tomcatpath + "//webapps//" + webFront + "//static//globalParams.json.bak";
                                        String basePaths = JsonUtils.readJsonFile( path );
                                        JSONObject jsonObject = JSON.parseObject( basePaths );
                                        //todo property要统一
                                        final String interfecePath = jsonObject.getString( "communicationAddressTestDataComparexcmp" );
                                        System.out.println( webList.get( i ) + " project's interfece path ::" + interfecePath );
                                        String[] split = interfecePath.split( ":" );
                                        StringBuffer buffer = new StringBuffer();
                                        for (int f = 0; f < split.length; f++) {
                                            System.out.println( split[f] );
                                        }
                                        int portEndPos = interfecePath.split( ":" )[2].indexOf( "/" );
                                        String s = interfecePath.split( ":" )[2].substring( portEndPos );
                                        try {
                                            address = InetAddress.getLocalHost();
                                            hostAddress = address.getHostAddress();
                                            System.out.println( "current IPaddress:: " + hostAddress );
                                        } catch (UnknownHostException e) {
                                            e.printStackTrace();
                                        }
                                        buffer.append( "http://" + hostAddress + ":" ).append( tomcatPort ).append( s );
                                        System.out.println( "the end:" + buffer.toString() );
                                        jsonObject.put( "communicationAddressTestDataComparexcmp", buffer.toString() );
                                        //wait tooltip
                                        if (!updateSuccess) {
                                            SBTFxDialog.showMessageDialog( stage, "当前项目" + webList.get( i ) + "正在配置路由，请耐心等待！", webList.get( i ) + "项目配置提示" );
                                        }
                                        updateSuccess = JsonUtils.writeJsonFile( jsonObject.toString(), path, pathNew );
                                        //update dataBase
                                        if (updateSuccess) {
                                            if (!reloadWebFront) {
                                                SBTFxDialog.showMessageDialog( stage, "当前项目" + webList.get( i ) + "正在重新加载，请耐心等待！", webList.get( i ) + "项目配置提示" );
                                            }
                                            //reload webFront  耗时等待
                                            reloadWebFront = TomcatHTMLUtil.reloadWebApp( webFront, tomcatPort );
                                            System.out.println( webList.get( i ) + " front page reload status :: " + reloadWebFront );
                                        }

                                    }
                                    if (webData.equals( web.getName() ) && "运行".equals( web.getStatus() )) {
                                        //update web database config
                                    *//*String webdatatWar = GlobalConfInfo.getProjectMap().get( webList.get( i ) ).split( "," )[1]
                                            .split( ":" )[1];
                                    String webData = webdatatWar.substring( 0, webdatatWar.lastIndexOf( "." ) );*//*
                                        String pathdata = tomcatpath + "/webapps/" + webData + "/WEB-INF/classes/application.properties";
                                        Configuration configuration = new Configuration( pathdata );
                                        //String value = "jdbc:mysql://" + text + ":3306/hrms?useUnicode=true&characterEncoding=UTF-8&useSSL=false";
                                        String pass = text;
                                        String usern = text1;
                                        if (!updatePro) {
                                            SBTFxDialog.showMessageDialog( stage, "当前项目" + webList.get( i ) + "正在更新数据源配置，请耐心等待！", webList.get( i ) + "项目配置提示" );
                                        }
                                        updatePro = configuration.updatePros( pathdata, "spring.datasource.username", usern, "spring.datasource.password", pass );
                                        if (updatePro) {
                                            boolean reloadWebApp = TomcatHTMLUtil.reloadWebApp( webData, tomcatPort );
                                            if (reloadWebApp) {
                                                count = 5;
                                                SBTFxDialog.showMessageDialog( stage, "当前项目" + webList.get( i ) + "启动成功 !，请到浏览器访问*****", "web项目成功启动提示" );
                                            }
                                        }

                                    }
                                }
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            } catch (ExecutionException e) {
                                e.printStackTrace();
                            }*/
                        }
                    }

                } else {
                    SBTFxDialog.showMessageDialog( stage, "请输入后台数据库密码！", "web项目安装提示" );
                }
            }
            //String excuteBatFile = BatUtils.excuteBatFile( tomcatpath + "\\bin\\startup.bat", true );
        }
    }

    /**
     * TomcatAction
     *
     * @return
     */
    private Boolean actTomcat() {
        SBTFxDialog.showMessageDialog( stage, "您正在启动" + currentProjectName + "项目，请确定是否继续 !", "启动web项目提示" );
        //BatUtils.excuteBatFile( tomcatpath + "\\bin\\shutdown.bat",true );
        //String excuteBatFile = BatUtils.excuteBatFile( tomcatpath + "\\bin\\startup.bat", true );
        Firing firing = new Firing();
        Task task = null;
        if (StringUtils.isWindowPath( tomcatpath )) {
            task = firing.excutetomcat( tomcatpath + "\\bin\\startup.bat", true );
        }
        if (!StringUtils.isWindowPath( tomcatpath )) {
            task = firing.excutetomcatlinux( tomcatpath + "/bin/startup.sh" );
        }
        System.out.println( "当前Tomcat安装路径为：" + tomcatpath );
        Thread thread = new Thread( task, "start" );
        thread.start();
        try {
            Thread.sleep( 3000 );
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        label.textProperty().bind( task.messageProperty() );
        Boolean heartbeat = BatUtils.heartbeat();
        System.out.println( "first heartbeat*******" + heartbeat );
        return heartbeat;
    }

    public void installation(String process) {
        if (!"".equals( tomcatpath ) && null != tomcatpath) {
            if (webList.isEmpty()) {
                count = 2;
                SBTFxDialog.showMessageDialog( stage, "请选择需要安装的项目！", "web项目安装提示" );
            }
            if (!webList.isEmpty()) {
                for (int i = 0; i < webList.size(); i++) {
                    String text1 = webDataBaseUser[i].getText();
                    String text = webDataBasePass[i].getText();
                    String ip = webDataBaseIp[i].getText();
                    String port = webDataBasePort[i].getText();
                    if (null == text || "".equals( text ) || null == text1 || "".equals( text1 )) {
                        count = 3;
                        Alert alert = new Alert( Alert.AlertType.WARNING );
                        alert.setTitle( "提示" );
                        alert.setContentText( "用户名或密码不能为空，请重新输入!" );
                        alert.showAndWait();
                        return;
                    }
                    if (null == ip || "".equals( ip ) || null == port || "".equals( port )) {
                        count = 3;
                        Alert alert = new Alert( Alert.AlertType.WARNING );
                        alert.setTitle( "提示" );
                        alert.setContentText( "数据库IP或端口不能为空，请重新输入!" );
                        alert.showAndWait();
                        return;
                    }
                }
                vBox = progressFrom.addProcess( stage, label );
                grid.add( vBox, 2, 3 );
                installWebItem( webList, process );
                        /*try {
                            Thread.sleep( 2000 );
                        } catch (InterruptedException e1) {
                            e1.printStackTrace();
                        }*/
                count = 4;
                installWebConfig( webList, process );

            }
        } else {
            count = 1;
            SBTFxDialog.showMessageDialog( stage, "系统检测到Tomcat木有安装，请返回上一步安装Tomcat！", "web项目安装提示" );
        }
    }

}
